package com.acwing.partition36;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/19 9:05
 */
public class AC3564日期类 {

    private static int[] months = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    private static StreamTokenizer tokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    private static PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int t = nextInt();
        while (t-- > 0) {
            int year = nextInt(), month = nextInt(), day = nextInt();
            day++;
            if (day > months[month]) {
                day = 1;
                month++;
                if (month > 12) {
                    year++;
                    month = 1;
                }
            }
            writer.format("%04d-%02d-%02d\n", year, month, day);
        }
        writer.flush();
    }

    private static int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }
}
